//
//  ViewController.m
//  ClassifyShop
//
//  Created by yuyao on 15/2/25.
//  Copyright (c) 2015年 yuyao. All rights reserved.
//

#import "ViewController.h"
#import "MyLevelView.h"
#import "Masonry.h"
#import "MyView.h"
#import "AddView.h"
#import "GUIDefine.h"
#import "SearchResultViewController.h"
#import "NetWorkModal.h"
#import "RestaurantsViewController.h"
#import "JixiangMeishiViewController.h"
@interface ViewController ()<MyViewRemovedDelegate,MyLeveleViewDelegate,AddViewDelegate>{
    MyLevelView *mylv;
    UIButton *personButton;
    UIButton *doneButton;
    UIButton *addButton;
    AddView *addView;
    SearchResultViewController *searchResultViewController;
    RestaurantsViewController *restaurantsViewController;
    JixiangMeishiViewController *jixiangMeishiViewController;

    MyView *subview;//搜索 tag 100
    MyView *tuijiangView;//推荐 tag 101
    MyView *cantingView;//餐厅 tag 102
    MyView *jixiangView;//即享美食 tag 103
    MyView *gouwuView;//购物车 tag 104
    MyView *shoucangView;//收藏 tag 105
    MyView *zuijinView;//最近浏览 tag 106
    MyView *dingdanView;//订单 tag 107

}

@end

@implementation ViewController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    
    if (self) {
        
        [self.view setBackgroundColor:[[UIColor alloc] initWithPatternImage:[appDelegate scaleToSize:[UIImage imageNamed:@"背景.png"] size:CGSizeMake(self.view.frame.size.width,self.view.frame.size.height-20)]]];

        personButton = [UIButton buttonWithType:UIButtonTypeCustom];
        personButton.frame = CGRectMake(0, 0, 25, 25);
        [personButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
      //  [personButton setTitle:@"个人" forState:UIControlStateNormal];
        [personButton setBackgroundImage:[UIImage imageNamed:@"用户.png"] forState:UIControlStateNormal];
        [personButton setTag:102];
        [personButton addTarget:self action:@selector(itemButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [[personButton  titleLabel] setFont:[UIFont systemFontOfSize:12]];
        [personButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 10, 0, 0)];
 
        addButton = [UIButton buttonWithType:UIButtonTypeCustom];
        addButton.frame = CGRectMake(0, 0, 25, 25);
        [addButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
       // [addButton setTitle:@"添加" forState:UIControlStateNormal];
        [addButton setBackgroundImage:[UIImage imageNamed:@"添加.png"] forState:UIControlStateNormal];
        [addButton setTag:101];
        [addButton addTarget:self action:@selector(itemButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [[addButton  titleLabel] setFont:[UIFont systemFontOfSize:12]];
        [addButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 10, 0, 0)];
        [addButton setHidden:YES];
        
        UIBarButtonItem *personButtonItem = [[UIBarButtonItem alloc] initWithCustomView:personButton];
        self.navigationItem.rightBarButtonItem = personButtonItem;
        doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
        doneButton.frame = CGRectMake(0, 0, 50, 25);
        [doneButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
     //   [doneButton setTitle:@"确定" forState:UIControlStateNormal];
        [doneButton setBackgroundImage:[UIImage imageNamed:@"确定按钮.png"] forState:UIControlStateNormal];
        [doneButton setTag:100];
        [doneButton addTarget:self action:@selector(itemButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [[doneButton  titleLabel] setFont:[UIFont systemFontOfSize:12]];
        [doneButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 10, 0, 0)];
        
        
        UIBarButtonItem *doneButtonItem = [[UIBarButtonItem alloc] initWithCustomView:doneButton];
        [doneButton setHidden:YES];
        self.navigationItem.leftBarButtonItem = doneButtonItem;
        

        
        
        
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];


    
    subview = [[MyView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width-2*leftPadding, 180)];
    [subview setTag:100];
    [subview setViewId:100];
    UIImageView *searchBack = [[UIImageView  alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width-2*leftPadding, 180)];
    [searchBack setImage:[UIImage imageNamed:@"外框 无阴影.png"]];
    [subview addSubview:searchBack];
    [subview setRemoveDelegate:self];


    
    UILabel *label = [[UILabel alloc] init];
    [label setText:@"搜索"];
    [label setFont:[UIFont fontWithName:@"Arial" size:14]];
    [label setTextAlignment:NSTextAlignmentCenter];

    [label setTextColor:[UIColor grayColor]];
    [subview addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(subview);
        make.top.equalTo(subview.mas_top).with.offset(10);
        make.size.mas_equalTo(CGSizeMake(80, 25));

    }];
    

    
    UIImageView *searchImage = [UIImageView new];
    [searchImage setImage:[appDelegate scaleToSize:[UIImage imageNamed:@"搜索.png"] size:CGSizeMake(subview.frame.size.width-50, (subview.frame.size.width-50)/10)]];
    [subview addSubview:searchImage];
    [searchImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(subview);
        make.top.equalTo(subview.mas_top).with.offset(54);
    }];
    
    
    UITextField *searchField = [UITextField new];
    [searchField setTag:2000];
    [searchField setFont:[UIFont fontWithName:@"Arial" size:13]];
    [searchField setClearButtonMode:UITextFieldViewModeWhileEditing];
    [searchField setReturnKeyType:UIReturnKeySearch];
    [searchField addTarget:self action:@selector(searchAction:) forControlEvents:UIControlEventEditingDidEndOnExit];
    [subview addSubview:searchField];
    [searchField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(subview).with.offset(30);
        make.top.equalTo(subview.mas_top).with.offset(54);
        make.size.mas_equalTo(CGSizeMake(subview.frame.size.width-100, (subview.frame.size.width-50)/10));
        
    }];
    
    UIImageView *leftImage = [UIImageView  new];
    [leftImage setImage:[appDelegate scaleToSize:[UIImage imageNamed:@"左.png"] size:CGSizeMake(60, 20)]];
    [subview addSubview:leftImage];
    [leftImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(searchImage);
        make.top.equalTo(searchImage.mas_bottom).with.offset(20);
    }];
    
    UIImageView *rightImage = [UIImageView  new];
    [rightImage setImage:[appDelegate scaleToSize:[UIImage imageNamed:@"右.png"] size:CGSizeMake(60, 20)]];
    [subview addSubview:rightImage];
    [rightImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(searchImage);
        make.top.equalTo(searchImage.mas_bottom).with.offset(20);
    }];
    
    UIImageView *englishImage = [UIImageView  new];
    [englishImage setImage:[appDelegate scaleToSize:[UIImage imageNamed:@"英文.png"] size:CGSizeMake(80, 9)]];
    [subview addSubview:englishImage];
    [englishImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(searchImage);
        make.top.equalTo(searchImage.mas_bottom).with.offset(33);
    }];
    
    ////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////

 
    tuijiangView = [[MyView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width-2*leftPadding, viewHeight)];
    [tuijiangView setRemoveDelegate:self];
    [tuijiangView setViewId:101];
    [tuijiangView setTag:101];
    UIImageView *tuijianbackImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,self.view.frame.size.width-2*leftPadding , viewHeight)];
    [tuijianbackImage setImage:[UIImage imageNamed:@"大框 无阴影.png"]];
    [tuijiangView addSubview:tuijianbackImage];
    
    UILabel *label2 = [[UILabel alloc] init];
    [label2 setText:@"推荐"];
    [label2 setFont:[UIFont fontWithName:@"Arial" size:14]];
    [label2 setTextAlignment:NSTextAlignmentCenter];
    [label2 setTextColor:[UIColor grayColor]];
    [tuijiangView addSubview:label2];
    [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(tuijiangView);
        make.top.equalTo(tuijiangView.mas_top).with.offset(15);
        make.size.mas_equalTo(CGSizeMake(80, 25));
        
    }];
    
    UIImageView *tuijianImage = [UIImageView new];
    [tuijiangView addSubview:tuijianImage];
    [tuijianImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(tuijiangView);
        make.top.equalTo(tuijiangView.mas_top).with.offset(40);
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width-2*leftPadding,(self.view.frame.size.width-2*leftPadding)*0.9));
        
    }];

    [tuijianImage setImage:[UIImage imageNamed:@"2 推荐.png"]];
    
    
//    UIImageView *moreImage = [UIImageView new];
//    [tuijiangView addSubview:moreImage];
//    [moreImage mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.equalTo(tuijiangView);
//        make.bottom.equalTo(tuijiangView);
//        make.size.mas_equalTo(CGSizeMake(tuijiangView.frame.size.width,tuijiangView.frame.size.width/6.5));
//        
//    }];
//    
//    [moreImage setImage:[UIImage imageNamed:@"more.png"]];

 
    ////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////
    
    cantingView = [[MyView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width-2*leftPadding, viewHeight)];

    [cantingView setBackgroundColor:[UIColor greenColor]];
    [cantingView setRemoveDelegate:self];
    [cantingView setTag:102];
    [cantingView setViewId:102];

    UIImageView *backImage3 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,self.view.frame.size.width-2*leftPadding , viewHeight)];
    [backImage3 setImage:[UIImage imageNamed:@"大框 无阴影.png"]];
    [cantingView addSubview:backImage3];
    
    
    UILabel *label3 = [[UILabel alloc] init];
    [label3 setText:@"餐厅"];
    [label3 setFont:[UIFont fontWithName:@"Arial" size:14]];
    [label3 setTextAlignment:NSTextAlignmentCenter];
    [label3 setTextColor:[UIColor grayColor]];
    [cantingView addSubview:label3];
    [label3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(cantingView);
        make.top.equalTo(cantingView.mas_top).with.offset(15);
        make.size.mas_equalTo(CGSizeMake(80, 25));
        
    }];
    
    UIImageView *cantingImage = [UIImageView new];
    [cantingView addSubview:cantingImage];
    [cantingImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(cantingView);
        make.top.equalTo(cantingView.mas_top).with.offset(40);
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width-2*leftPadding,(self.view.frame.size.width-2*leftPadding)*0.9));
        
    }];
    
    [cantingImage setImage:[UIImage imageNamed:@"3 餐厅.png"]];
    
    
    
    UIButton *overButton = [UIButton new];
    [overButton setTag:102];
    [overButton addTarget:self action:@selector(moreButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [cantingView addSubview:overButton];
    [overButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(cantingView);
        make.top.equalTo(cantingView.mas_top).with.offset(40);
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width-2*leftPadding,(self.view.frame.size.width-2*leftPadding)*0.9));
        
    }];
    
    
//    UIButton *moreImage3 = [UIButton new];
//    [moreImage3 setTag:102];
//    [moreImage3 addTarget:self action:@selector(moreButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
//    [cantingView addSubview:moreImage3];
//    [moreImage3 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.equalTo(cantingView);
//        make.bottom.equalTo(cantingView);
//        make.size.mas_equalTo(CGSizeMake(cantingView.frame.size.width,cantingView.frame.size.width/6.5));
//        
//    }];
//    
//    [moreImage3 setBackgroundImage:[UIImage imageNamed:@"more.png"] forState:UIControlStateNormal];
    
    ////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////
    
    jixiangView = [[MyView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width-2*leftPadding, viewHeight)];

    [jixiangView setBackgroundColor:[UIColor grayColor]];
    [jixiangView setRemoveDelegate:self];
    [jixiangView setTag:103];
    [jixiangView setViewId:103];

    UIImageView *backImage4 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,self.view.frame.size.width-2*leftPadding , viewHeight)];
    [backImage4 setImage:[UIImage imageNamed:@"大框 无阴影.png"]];
    [jixiangView addSubview:backImage4];
    
    
    UILabel *label4 = [[UILabel alloc] init];
    [label4 setText:@"即享美食"];
    [label4 setFont:[UIFont fontWithName:@"Arial" size:14]];
    [label4 setTextAlignment:NSTextAlignmentCenter];
    [label4 setTextColor:[UIColor grayColor]];
    [jixiangView addSubview:label4];
    [label4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(jixiangView);
        make.top.equalTo(jixiangView.mas_top).with.offset(15);
        make.size.mas_equalTo(CGSizeMake(80, 25));
        
    }];
    
    UIImageView *jixiangImage = [UIImageView new];
    [jixiangView addSubview:jixiangImage];
    [jixiangImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(jixiangView);
        make.top.equalTo(jixiangView.mas_top).with.offset(42);
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width-2*leftPadding,(self.view.frame.size.width-2*leftPadding)*0.9));
        
    }];
    
    [jixiangImage setImage:[UIImage imageNamed:@"4 即享美食.png"]];
    
    
    
    UIButton *overButton3 = [UIButton new];
    [overButton3 setTag:103];
    [overButton3 addTarget:self action:@selector(moreButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [jixiangView addSubview:overButton3];
    [overButton3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(jixiangImage);
        make.top.equalTo(jixiangImage.mas_top).with.offset(40);
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width-2*leftPadding,(self.view.frame.size.width-2*leftPadding)*0.9));
        
    }];
    
//    UIImageView *moreImage4 = [UIImageView new];
//    [jixiangView addSubview:moreImage4];
//    [moreImage4 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.equalTo(jixiangView);
//        make.bottom.equalTo(jixiangView);
//        make.size.mas_equalTo(CGSizeMake(jixiangView.frame.size.width,jixiangView.frame.size.width/6.5));
//        
//    }];
//    
//    [moreImage4 setImage:[UIImage imageNamed:@"more.png"]];
    
    ////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////
  
    gouwuView = [[MyView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width-2*leftPadding, viewHeight)];

    [gouwuView setBackgroundColor:[UIColor purpleColor]];
    [gouwuView setRemoveDelegate:self];
    [gouwuView setTag:104];
    [gouwuView setViewId:104];
    
    UIImageView *backImage5 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,self.view.frame.size.width-2*leftPadding , viewHeight)];
    [backImage5 setImage:[UIImage imageNamed:@"大框 无阴影.png"]];
    [gouwuView addSubview:backImage5];
   
    
    UILabel *label5 = [[UILabel alloc] init];
    [label5 setText:@"购物车"];
    [label5 setFont:[UIFont fontWithName:@"Arial" size:14]];
    [label5 setTextAlignment:NSTextAlignmentCenter];
    [label5 setTextColor:[UIColor grayColor]];
    [gouwuView addSubview:label5];
    [label5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(gouwuView);
        make.top.equalTo(gouwuView.mas_top).with.offset(15);
        make.size.mas_equalTo(CGSizeMake(80, 25));
        
    }];

    UIImageView *gouwucheImage = [UIImageView new];
    [gouwuView addSubview:gouwucheImage];
    [gouwucheImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(gouwuView);
        make.top.equalTo(gouwuView.mas_top).with.offset(40);
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width-2*leftPadding,(self.view.frame.size.width-2*leftPadding)*0.9));
        
    }];
    
    [gouwucheImage setImage:[UIImage imageNamed:@"5 购物车.png"]];
    
    
    
//    UIImageView *moreImage5 = [UIImageView new];
//    [gouwuView addSubview:moreImage5];
//    [moreImage5 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.equalTo(gouwuView);
//        make.bottom.equalTo(gouwuView);
//        make.size.mas_equalTo(CGSizeMake(gouwuView.frame.size.width,gouwuView.frame.size.width/6.5));
//        
//    }];
//    
//    [moreImage5 setImage:[UIImage imageNamed:@"more.png"]];
    
    ////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////
    
    shoucangView = [[MyView alloc] initWithFrame:CGRectMake(leftPadding, self.view.frame.size.height, self.view.frame.size.width-2*leftPadding, viewHeight)];
    
    [shoucangView setRemoveDelegate:self];
    [shoucangView.layer setShadowOpacity:0.8];
    [shoucangView.layer setShadowOffset:CGSizeMake(0.f,-.5f)];
    [shoucangView setTag:105];
    [shoucangView setViewId:105];

    
    UILabel *label6 = [[UILabel alloc] init];
    [label6 setText:@"收藏"];
    [label6 setFont:[UIFont fontWithName:@"Arial" size:14]];
    [label6 setTextAlignment:NSTextAlignmentCenter];
    [label6 setTextColor:[UIColor grayColor]];
    [shoucangView addSubview:label6];
    [label6 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(shoucangView);
        make.top.equalTo(shoucangView.mas_top).with.offset(15);
        make.size.mas_equalTo(CGSizeMake(80, 25));
        
    }];

    
//    UIImageView *moreImage6 = [UIImageView new];
//    [shoucangView addSubview:moreImage6];
//    [moreImage6 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.equalTo(shoucangView);
//        make.bottom.equalTo(shoucangView);
//        make.size.mas_equalTo(CGSizeMake(shoucangView.frame.size.width,shoucangView.frame.size.width/6.5));
//        
//    }];
//    
//    [moreImage6 setImage:[UIImage imageNamed:@"more.png"]];
    
    
    ////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////
    
    zuijinView = [[MyView alloc] initWithFrame:CGRectMake(leftPadding, self.view.frame.size.height, self.view.frame.size.width-2*leftPadding, viewHeight)];
    
    [zuijinView setRemoveDelegate:self];
    [zuijinView.layer setShadowOpacity:0.8];
    [zuijinView.layer setShadowOffset:CGSizeMake(0.f,-.5f)];
    [zuijinView setTag:106];
    [zuijinView setViewId:106];

    
    UILabel *label7 = [[UILabel alloc] init];
    [label7 setText:@"最近浏览"];
    [label7 setFont:[UIFont fontWithName:@"Arial" size:14]];
    [label7 setTextAlignment:NSTextAlignmentCenter];
    [label7 setTextColor:[UIColor grayColor]];
    [zuijinView addSubview:label7];
    [label7 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(zuijinView);
        make.top.equalTo(zuijinView.mas_top).with.offset(15);
        make.size.mas_equalTo(CGSizeMake(80, 25));
        
    }];
    
    
//    UIImageView *moreImage7 = [UIImageView new];
//    [zuijinView addSubview:moreImage7];
//    [moreImage7 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.equalTo(zuijinView);
//        make.bottom.equalTo(zuijinView);
//        make.size.mas_equalTo(CGSizeMake(zuijinView.frame.size.width,zuijinView.frame.size.width/6.5));
//        
//    }];
//    
//    [moreImage7 setImage:[UIImage imageNamed:@"more.png"]];
    
    
    ////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////
    
    dingdanView = [[MyView alloc] initWithFrame:CGRectMake(leftPadding, self.view.frame.size.height, self.view.frame.size.width-2*leftPadding, viewHeight)];
    
    [dingdanView setRemoveDelegate:self];
    [dingdanView.layer setShadowOpacity:0.8];
    [dingdanView.layer setShadowOffset:CGSizeMake(0.f,-.5f)];
    [dingdanView setTag:107];
    [dingdanView setViewId:107];

    
    UILabel *label8 = [[UILabel alloc] init];
    [label8 setText:@"订单"];
    [label8 setFont:[UIFont fontWithName:@"Arial" size:14]];
    [label8 setTextAlignment:NSTextAlignmentCenter];
    [label8 setTextColor:[UIColor grayColor]];
    [dingdanView addSubview:label8];
    [label8 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(dingdanView);
        make.top.equalTo(dingdanView.mas_top).with.offset(15);
        make.size.mas_equalTo(CGSizeMake(80, 25));
        
    }];
    
    
//    UIImageView *moreImage8 = [UIImageView new];
//    [dingdanView addSubview:moreImage8];
//    [moreImage8 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.equalTo(dingdanView);
//        make.bottom.equalTo(dingdanView);
//        make.size.mas_equalTo(CGSizeMake(dingdanView.frame.size.width,dingdanView.frame.size.width/6.5));
//        
//    }];
//    
//    [moreImage8 setImage:[UIImage imageNamed:@"more.png"]];
    
    
   // NSArray *views = [NSArray arrayWithObjects:subview,tuijiangView,cantingView,jixiangView,gouwuView, nil];
    
    NSMutableArray *views = [NSMutableArray array];

    NSArray *viewTags = [appDelegate getTags];
    
    [views addObject:subview];
    
    if ([viewTags containsObject:[NSNumber numberWithInt:tuijiangView.viewId]]) {
        [views addObject:tuijiangView];
    }
    if ([viewTags containsObject:[NSNumber numberWithInt:cantingView.viewId]]) {
        [views addObject:cantingView];
    }
    if ([viewTags containsObject:[NSNumber numberWithInt:jixiangView.viewId]]) {
        [views addObject:jixiangView];
    }
    if ([viewTags containsObject:[NSNumber numberWithInt:gouwuView.viewId]]) {
        [views addObject:gouwuView];
    }
    if ([viewTags containsObject:[NSNumber numberWithInt:shoucangView.viewId]]) {
        [views addObject:shoucangView];
    }
    if ([viewTags containsObject:[NSNumber numberWithInt:zuijinView.viewId]]) {
        [views addObject:zuijinView];
    }
    if ([viewTags containsObject:[NSNumber numberWithInt:dingdanView.viewId]]) {
        [views addObject:dingdanView];
    }
    
    
    
    mylv = [[MyLevelView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) andViews:views];
    [mylv setMydelegate:self];
    [self.view addSubview:mylv];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];

}
#pragma mark more
- (void)moreButtonPressed:(id)sender{
    UIImageView *titleBackImage = (UIImageView *)[self.navigationController.navigationBar viewWithTag:123];
    [UIView animateWithDuration:0.2 animations:^{
        [titleBackImage setAlpha:0];
    }];
    
    UIButton *btn = (UIButton *)sender;
    switch ((int)btn.tag) {
        case 100:{
            
        }
            
            break;
        case 101:{
            
        }
            
            break;
        case 102:{
            
        
            if (restaurantsViewController==nil) {
                    restaurantsViewController = [[RestaurantsViewController alloc] initWithNibName:nil bundle:nil];
            }
            restaurantsViewController.title = @"餐厅";
            
            [restaurantsViewController getAllRestaurants];

            [self.navigationController pushViewController:restaurantsViewController animated:YES];
        }
            
            break;
        case 103:{
            if (jixiangMeishiViewController==nil) {
                jixiangMeishiViewController = [[JixiangMeishiViewController alloc] initWithNibName:nil bundle:nil];
            }
            jixiangMeishiViewController.title = @"即享美食";
            
            [jixiangMeishiViewController getAllRestaurants];
            
            [self.navigationController pushViewController:jixiangMeishiViewController animated:YES];
        }
            
            break;
        case 104:{
            
        }
            
            break;
        case 105:{
            
        }
            
            break;
        default:
            break;
    }

}
#pragma mark 搜索
- (void)searchAction:(id)sender{
    UITextField *tf = (UITextField *)sender;
    
    UIImageView *titleBackImage = (UIImageView *)[self.navigationController.navigationBar viewWithTag:123];

    [UIView animateWithDuration:0.2 animations:^{
            [titleBackImage setAlpha:0];
    }];

    
    if (searchResultViewController==nil) {
        searchResultViewController = [[SearchResultViewController alloc] initWithNibName:nil bundle:nil];
    }
    [searchResultViewController getRestaurantWithKeyword:tf.text];
    searchResultViewController.title = @"搜索结果";
    [self.navigationController pushViewController:searchResultViewController animated:YES];
    
}
#pragma mark tabbar button 按钮
- (void)itemButtonPressed:(id)sender{

    UIButton *btn = (UIButton *)sender;
    switch (btn.tag) {
        case 100:{//确定
            [doneButton setHidden:YES];
            [addButton setHidden:YES];
            [personButton setHidden:NO];
            UIBarButtonItem *personButtonItem = [[UIBarButtonItem alloc] initWithCustomView:personButton];
            self.navigationItem.rightBarButtonItem = personButtonItem;

            [mylv endEditting];
        }
            break;
        case 101:{//添加
            if (addView==nil) {
                addView = [[AddView alloc] initWithFrame:[UIScreen mainScreen].bounds];
                [addView setDelegate:self];
            }
            [addView refreshAddButtons];
            if (addView.superview==nil) {
                [self.navigationController.view addSubview:addView];
            }
        }
            
            break;
        case 102:{//个人
            
        }

            break;
        default:
            break;
    }
}
#pragma mark 删除view 代理
- (void)removedToReloadViews:(int)vid{
    
    switch (vid) {
        case 101:{//推荐 viewId 101
            
            [tuijiangView removeFromSuperview];
            [mylv addOrRemoveView:tuijiangView Boo:NO];//yes 加 no 删
            

            
        }
            break;
        case 102:{//餐厅 viewId 102
            
            [cantingView removeFromSuperview];
            [mylv addOrRemoveView:cantingView Boo:NO];
            


            
        }
            break;
        case 103:{//即享美食 viewId 103
            
            [mylv addOrRemoveView:jixiangView Boo:NO];
            [jixiangView removeFromSuperview];

            
        }
            break;
        case 104:{//购物车 viewId 104
            
            [mylv addOrRemoveView:gouwuView Boo:NO];
            [gouwuView removeFromSuperview];

            
        }
            break;
        case 105:{//收藏 viewId 105
            
            [mylv addOrRemoveView:shoucangView Boo:NO];
            [shoucangView removeFromSuperview];
            
            
            
        }
            break;
        case 106:{//最近浏览 viewId 106
            
            [mylv addOrRemoveView:zuijinView Boo:NO];
            [zuijinView removeFromSuperview];
            
        
            
        }
            break;
        case 107:{ //订单 viewId 107
            
            [mylv addOrRemoveView:dingdanView Boo:NO];
            [dingdanView removeFromSuperview];
            
            
        }
            break;
            
        default:
            break;
    }

    
    

    MyView *mv2 = (MyView *)[mylv viewWithTag:100];

    UIGestureRecognizer *gr = [[UIGestureRecognizer alloc] init];
    [mv2 addGestureRecognizer:gr];
    [mylv tapped:gr];
    

    
}
#pragma  mark MyLeveleViewDelegate

- (void)selectedViewWithIndex:(int)index{
    UITextField *tf = (UITextField *)[self.view viewWithTag:2000];
    [tf resignFirstResponder];

    
 }
- (void)editingModal{
    
    UIBarButtonItem *addButtonItem = [[UIBarButtonItem alloc] initWithCustomView:addButton];
    self.navigationItem.rightBarButtonItem = addButtonItem;
    [doneButton setHidden:NO];
    [addButton setHidden:NO];
    [personButton setHidden:YES];
}
#pragma mark AddViewDelegate
- (void)didSeletedAddViewIndex:(int)vid{
   
    
    switch (vid) {
        case 101:{//推荐 viewId 101

            
            [tuijiangView setTag:tuijiangView.viewId];

            [mylv addOrRemoveView:tuijiangView Boo:YES];

        }
            break;
        case 102:{//餐厅 viewId 102

            [mylv addOrRemoveView:cantingView Boo:YES];

        }
            break;
        case 103:{//即享美食 viewId 103
            
            [mylv addOrRemoveView:jixiangView Boo:YES];

            
        }
            break;
        case 104:{//购物车 viewId 104

            [mylv addOrRemoveView:gouwuView Boo:YES];

        }
            break;
        case 105:{//收藏 viewId 105

            [mylv addOrRemoveView:shoucangView Boo:YES];

        }
            break;
        case 106:{//最近浏览 viewId 106
            
            [mylv addOrRemoveView:zuijinView Boo:YES];

            
        }
            break;
        case 107:{ //订单 viewId 107
            
            [mylv addOrRemoveView:dingdanView Boo:YES];

        }
            break;

        default:
            break;
    }

    
    MyView *mv2 = (MyView *)[mylv viewWithTag:100];
    
    UIGestureRecognizer *gr = [[UIGestureRecognizer alloc] init];
    [mv2 addGestureRecognizer:gr];
    [mylv tapped:gr];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
